# include <stdio.h>

int main()
{
    int n;
    scanf("%d", &n);
    int a[10] = {0};
    scanf("%d", &a[0]);
    int minN, maxN, minK = 0, maxK = 0;
    minN = maxN = a[0];
    for (int i = 1; i < n; i++)
    {
        scanf("%d", &a[i]);
        if (a[i] > maxN)
        {
            maxN = a[i];
            maxK = i;
        }
        else if(a[i] < minN)
        {
            minN = a[i];
            minK = i;
        }
    }
    int temp;
    temp = a[0];
    a[0] = minN;
    a[minK] = temp;
    if (a[minK] == maxN)
    {
        maxK = minK;
    }
    temp = a[n - 1];
    a[n - 1] = maxN;
    a[maxK] = temp;
    for (int k = 0; k < n; k++)
    {
        printf("%d ", a[k]);
    }
    return 0;
}